import 'package:flutter/material.dart';
import 'package:hzcloud_flt/common/hz_loading/hz_base_loading.dart';
import 'package:hzcloud_flt/models/banner.dart';

import 'hz_loading/hz_loading_dialog.dart';
import 'hz_network/hz_network.dart';

class HZNetworkTest extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _HZNetworkTestState();
  }
}

class _HZNetworkTestState extends State<HZNetworkTest> {
  BannerInfo _bannerInfo;
  String title = "哈哈";
  Future getList;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getList = request();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            title = title + '.';
          });
        },
        child: Icon(Icons.title),
      ),
      body: HZBaseLoading(
        future: getList,
        builder: (_, data) {
          return Text('${(data as BannerInfo).toJson()}');
        },
      ),
    );
  }

  Future request() {
    var data = {"ParkID": "R3711012020041111111", "code": "main", "q": "code"};
    HZNetworkConfig config = HZNetworkConfig(
      HZNetworkFetchMethod.get,
      '/p/sps/api/v1/public/banners',
      data: data,
    );
    return HZNetwork.request(config).then((response) {
      return BannerInfo.fromJson(response.data);
    }).catchError((error) {});
  }
}
